Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add range based exponential buckets in histogram #233

Merged
merged 8 commits into from
Jan 7, 2025

Conversation

kohlisid
Copy link
Contributor

The current implementation does not have a range based exponential bucket function.

This can be useful in scenarios where the end user doesn't want to perform manual calculations for extracting the required buckets, especially when multiple different ranges are to be used for different histograms.

Similar implementation is provided in the golang client as well.
https://github.com/prometheus/client_golang/blob/5d584e2717ef525673736d72cd1d12e304f243d7/prometheus/histogram.go#L125

@kohlisid kohlisid marked this pull request as ready for review October 15, 2024 05:10
@kohlisid
Copy link
Contributor Author

@mxinden please check!
Thank you

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat. A couple of comments:

Comment on lines 130 to 132
if length < 1 {
panic!("ExponentialBucketsRange length needs a positive length");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a NonZeroU16 instead of a u16. That said, that would be inconsistent with exponential_buckets. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess better to keep as u16 to keep consistent with exponential_buckets.
We can keep the additional check in the code for correctness.
What do you think?

src/metrics/histogram.rs Outdated Show resolved Hide resolved
Comment on lines 133 to 135
if min <= 0.0 {
panic!("ExponentialBucketsRange min needs to be greater than 0");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't panic anywhere else in the crate. Reason being, that given that instrumentation is auxiliary only, folks likely don't want a panic. Would an empty Iterator work too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I have removed panics, but instead of an empty iterator I have added defaults with a warning.
Empty iterator might have have side-effects in histogram functionality.
Wdyt?

src/registry.rs Outdated Show resolved Hide resolved
Sidhant Kohli added 2 commits October 29, 2024 10:18
Signed-off-by: Sidhant Kohli <[email protected]>
Signed-off-by: Sidhant Kohli <[email protected]>
@kohlisid kohlisid requested a review from mxinden October 29, 2024 14:20
@kohlisid
Copy link
Contributor Author

@mxinden Thanks for the review! Have addressed them with some small follow ups, please take a look whenever you get a chance.

@kohlisid
Copy link
Contributor Author

kohlisid commented Nov 6, 2024

@mxinden Just following up on this? Let me know if any other changes are required

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here.

Unfortunately adding a log statement is not an option.

What is the issue with returning an empty iterator?

Alternatively we can change the function to return a Result.

Cargo.toml Outdated
@@ -24,6 +24,7 @@ parking_lot = "0.12"
prometheus-client-derive-encode = { version = "0.4.1", path = "derive-encode" }
prost = { version = "0.12.0", optional = true }
prost-types = { version = "0.12.0", optional = true }
log = "0.4.22"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to keep the dependency footprint of this crate as small as possible. Adding log just for this use-case is not an option. Mind reverting it?

@kohlisid
Copy link
Contributor Author

kohlisid commented Jan 6, 2025

Hey @mxinden
Thanks for getting back on this
I can remove the log here for sure!
Returning the result might be cleaner but then it would diverge from the fixed buckets functions present currently, if you're okay with that we can go that route

Otherwise I'm good with having the empty iterator as return

Let me know what works best and I can make those changes quickly and we can get this merged :)

@kohlisid
Copy link
Contributor Author

kohlisid commented Jan 6, 2025

@mxinden Based on your latest addition to the change log file, could you please tell me what would be the conflict resolution here intended.

@kohlisid kohlisid requested a review from mxinden January 6, 2025 18:18
@mxinden
Copy link
Member

mxinden commented Jan 6, 2025

@kohlisid I resolved the merge conflicts. Sorry for the trouble.

Please remove the log dependency. You can keep the log lines as code comments. I am in favor of using an empty iterator.

Signed-off-by: Sidhant Kohli <[email protected]>
@kohlisid
Copy link
Contributor Author

kohlisid commented Jan 6, 2025

@mxinden Updated! Please check
Thanks

Signed-off-by: Max Inden <[email protected]>
@mxinden mxinden merged commit 8f13460 into prometheus:master Jan 7, 2025
10 checks passed
@kohlisid kohlisid deleted the hist-exp branch January 7, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants